﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace EOS.Framework.Tools
{
    public static class Guard
    {
        public static void Between<TType>(TType target, TType left, TType right, string paramName) where TType : IComparable
        {
            if (!target.IsBetween(left, right))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                    "Value must be between {0} and {1}", left, right));
            }
        }

        public static void Between<TType>(TType target, TType left, TType right, string paramName, string message) where TType : IComparable
        {
            if (!target.IsBetween(left, right))
            {
                throw new ArgumentException(message, paramName);
            }
        }

        public static void NotEmpty<TType>(ICollection<TType> enumerable, string paramName)
        {
            if (enumerable.Count == 0)
            {
                throw new ArgumentException("Collection does not contain an item", paramName);
            }
        }

        public static void NotEmpty<TType>(ICollection<TType> enumerable, string paramName, string message)
        {
            if (enumerable.Count == 0)
            {
                throw new ArgumentException(message, paramName);
            }
        }

        public static void NotNullOrEmpty(string target, string paramName)
        {
            if (target == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (StringHelper.IsEmptyOrBlanksOnly(target))
            {
                throw new ArgumentException("String parameter cannot be null or empty and cannot contain only blanks.", paramName);
            }
        }

        public static void NotNullOrEmpty(string target, string paramName, string message)
        {
            if (target == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (StringHelper.IsEmptyOrBlanksOnly(target))
            {
                throw new ArgumentException(message, paramName);
            }
        }

        public static void NotNull(object target, string paramName)
        {
            if (target == null)
            {
                throw new ArgumentNullException(paramName);
            }
        }

        public static void NotNull(object target, string paramName, string message)
        {
            if (target == null)
            {
                throw new ArgumentNullException(message, paramName);
            }
        }
    }
}
